import Vue from 'vue'
import i18n from './lang' // Internationalization
import axios from './utils/request'
import VueAxios from 'vue-axios'
import App from './App'
import router from './router/router'
import '@/assets/styles/index.scss' // index css
import '@/assets/styles/mips.scss' // mips css
import './permission' // 权限
import './error' // 日志
import './cache'// 页面缓冲
import store from './store'
import { loadStyle } from './util/util'
import * as urls from '@/config/env'
import Element from 'element-ui'
import locale from 'element-ui/lib/locale/lang/en'
import {
  iconfontUrl,
  iconfontVersion
} from '@/config/env'
import './styles/common.scss'
import './assets/icons' // icon
import basicBlock from './components/basic-block/main'
import basicContainer from './components/basic-container/main'
import crudCommon from '@/mixins/crud.js'
import { getDicts } from '@/api/system/dictData'
import { getByKey } from '@/api/system/config'
import { parseTime, newPath, resetForm, addDateRange, selectDictLabel, download, handleTree } from '@/utils/mips'// 全局方法挂载
import permission from './directive/permission'
import Pagination from '@/components/Pagination'

window.$crudCommon = crudCommon
Vue.prototype.getDicts = getDicts
Vue.prototype.getByKey = getByKey
Vue.prototype.parseTime = parseTime
Vue.prototype.newPath = newPath
Vue.prototype.resetForm = resetForm
Vue.prototype.addDateRange = addDateRange
Vue.prototype.selectDictLabel = selectDictLabel
Vue.prototype.download = download
Vue.prototype.handleTree = handleTree
Vue.prototype.$EventBus = new Vue()

Vue.prototype.msgSuccess = function(msg) {
  this.$message({ showClose: true, message: msg, type: 'success' })
}

Vue.prototype.msgWarning = function(msg) {
  this.$message({ showClose: true, message: msg, type: 'warning' })
}

Vue.prototype.msgError = function(msg) {
  this.$message({ showClose: true, message: msg, type: 'error' })
}

Vue.prototype.msgInfo = function(msg) {
  this.$message.info(msg)
}

Vue.use(permission)
Vue.use(router)
Vue.use(VueAxios, axios)
Vue.use(Element, { size: 'small', zIndex: 3000 })
Vue.use(Element, {
  i18n: (key, value) => i18n.t(key, value)
})
Vue.use(Element, { locale })
Vue.use(window.AVUE, {
  i18n: (key, value) => i18n.t(key, value)
})
// 注册全局容器
Vue.component('basicContainer', basicContainer)
Vue.component('basicBlock', basicBlock)
// 全局组件挂载
Vue.component('Pagination', Pagination)
// 加载相关url地址
Object.keys(urls).forEach(key => {
  Vue.prototype[key] = urls[key]
})

// 动态加载阿里云字体库
iconfontVersion.forEach(ele => {
  loadStyle(iconfontUrl.replace('$key', ele))
})

Vue.config.productionTip = false
Vue.prototype.$echarts = window.echarts
new Vue({
  router,
  store,
  i18n,
  render: h => h(App)
}).$mount('#app')
